#include "splitTool.h"

SplitTool * SplitTool::_pInstance = nullptr;

SplitTool::SplitTool()
: _jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,IDF_PATH,STOP_WORD_PATH)
{

}

void SplitTool::cutChineseWord(string filePath, vector<string> &words)
{
    ifstream ifs(filePath);
    stringstream file;
    //将打开的文件流 ifs 的内容读取到 stringstream 对象 file 中
    file << ifs.rdbuf();
    //使用jieba对file中的内容进行分词，结构存入words中
    _jieba.Cut(file.str(), words);
    ifs.close();
}

//cut英文单词
void SplitTool::cutEnglishWord(string str, vector<string> &words, int placeholder)
{
    istringstream ss(str);
    string word;
    while(ss >> word)
    {
        words.push_back(word);
    }
}

void SplitTool::cutChineseWord(string str, vector<string> &words, int placeholder)
{
    //使用jieba对内容进行分词，结果存入words中
    _jieba.Cut(str, words);
}

//cut英文单词
void SplitTool::cutEnglishWord(string filePath, vector<string> &words)
{
    ifstream ifs(filePath);

    string str_line;
    while(getline(ifs,str_line))
    {
        istringstream ss(str_line);
        string word;
        while(ss >> word)
        {
            words.push_back(word);
        }
    }
    //关闭文件
    ifs.close();
}